<?php

/**
 * This is the model class for table "{{user}}".
 *
 * The followings are the available columns in table '{{user}}':
 * @property integer $userID
 * @property string $first_name
 * @property string $last_name
 * @property string $user_name
 * @property string $emailID
 * @property string $user_type
 * @property string $password
 * @property integer $referenceID
 * @property integer $countryID
 * @property integer $user_cityID
 * @property integer $user_stateID
 * @property integer $zip_code
 * @property string $organisation
 * @property string $designation
 * @property string $activation_key
 * @property integer $total_points
 * @property integer $total_cash
 * @property string $profile_image
 * @property string $college_id_image
 * @property string $qualification
 * @property string $address
 * @property string $mobile_number
 * @property string $birth_date
 * @property string $gender
 * @property string $payment_status
 * @property string $payment_type
 * @property string $created
 * @property string $modified
 *
 * The followings are the available model relations:
 * @property Document[] $documents
 * @property Image[] $images
 * @property JobApplication[] $jobApplications
 * @property JobOtherDetails[] $jobOtherDetails
 * @property City $userCity
 * @property State $userState
 * @property Video[] $videos
 */
class User extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return User the static model class
	 */
public $cnfpassword;

    public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{user}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('user_cityID, user_stateID, zip_code, organisation, designation, password, first_name, emailID, qualification, mobile_number, address', 'required'),
			array('referenceID, countryID, user_cityID, user_stateID, zip_code, total_points, total_cash, mobile_number', 'numerical', 'integerOnly'=>true),
			array('first_name, last_name, user_name, user_type, password, activation_key, profile_image, qualification, address, payment_status, payment_type', 'length', 'max'=>100),
			array('mobile_number','length','max'=>'10'),
                        array('mobile_number','length','min'=>'10'),
                        array('zip_code','length','min'=>'6'),
                        array('zip_code','length','max'=>'8'),
                        array('emailID', 'length', 'max'=>200),
                        array('emailID','unique'),
                        array('emailID','email'),
                        array('cnfpassword','passwordauth'),
			array('organisation, designation, college_id_image', 'length', 'max'=>500),
			array('mobile_number', 'length', 'max'=>20),
			array('gender', 'length', 'max'=>45),
			array('birth_date, created, modified', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('userID, first_name, last_name, user_name, emailID, user_type, password, referenceID, countryID, user_cityID, user_stateID, zip_code, organisation, designation, activation_key, total_points, total_cash, profile_image, college_id_image, qualification, address, mobile_number, birth_date, gender, payment_status, payment_type, created, modified', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'documents' => array(self::HAS_MANY, 'Document', 'userID'),
			'images' => array(self::HAS_MANY, 'Image', 'userID'),
			'jobApplications' => array(self::HAS_MANY, 'JobApplication', 'applicantID'),
			'jobOtherDetails' => array(self::HAS_MANY, 'JobOtherDetails', 'userID'),
			'userCity' => array(self::BELONGS_TO, 'City', 'user_cityID'),
			'userState' => array(self::BELONGS_TO, 'State', 'user_stateID'),
			'videos' => array(self::HAS_MANY, 'Video', 'userID'),
		);
	}
        
        public function passwordauth()
        {
            if($this->password!=$this->cnfpassword)
            {
                $this->addError('cnfpassword', 'Passwords are not matching');
            }
        }

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'userID' => 'User',
			'first_name' => 'Name',
			'last_name' => 'Last Name',
			'user_name' => 'User Name',
			'emailID' => 'Email',
			'user_type' => 'User Type',
			'password' => 'Password',
			'referenceID' => 'Reference',
			'countryID' => 'Country',
			'user_cityID' => 'City',
			'user_stateID' => 'State',
			'zip_code' => 'Zip Code',
			'organisation' => 'Organisation',
			'designation' => 'Designation',
			'activation_key' => 'Activation Key',
			'total_points' => 'Total Points',
			'total_cash' => 'Total Cash',
			'profile_image' => 'Profile Image',
			'college_id_image' => 'College Id Image',
			'qualification' => 'Qualification',
			'address' => 'Address',
			'mobile_number' => 'Mobile Number',
			'birth_date' => 'Birth Date',
			'gender' => 'Gender',
			'payment_status' => 'Payment Status',
			'payment_type' => 'Payment Type',
			'created' => 'Created',
			'modified' => 'Modified',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('userID',$this->userID);
		$criteria->compare('first_name',$this->first_name,true);
		$criteria->compare('last_name',$this->last_name,true);
		$criteria->compare('user_name',$this->user_name,true);
		$criteria->compare('emailID',$this->emailID,true);
		$criteria->compare('user_type',$this->user_type,true);
		$criteria->compare('password',$this->password,true);
		$criteria->compare('referenceID',$this->referenceID);
		$criteria->compare('countryID',$this->countryID);
		$criteria->compare('user_cityID',$this->user_cityID);
		$criteria->compare('user_stateID',$this->user_stateID);
		$criteria->compare('zip_code',$this->zip_code);
		$criteria->compare('organisation',$this->organisation,true);
		$criteria->compare('designation',$this->designation,true);
		$criteria->compare('activation_key',$this->activation_key,true);
		$criteria->compare('total_points',$this->total_points);
		$criteria->compare('total_cash',$this->total_cash);
		$criteria->compare('profile_image',$this->profile_image,true);
		$criteria->compare('college_id_image',$this->college_id_image,true);
		$criteria->compare('qualification',$this->qualification,true);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('mobile_number',$this->mobile_number,true);
		$criteria->compare('birth_date',$this->birth_date,true);
		$criteria->compare('gender',$this->gender,true);
		$criteria->compare('payment_status',$this->payment_status,true);
		$criteria->compare('payment_type',$this->payment_type,true);
		$criteria->compare('created',$this->created,true);
		$criteria->compare('modified',$this->modified,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}